package com.settlement.system.service.impl;

import com.settlement.system.mapper.TblWpVendorConfigMapper;
import com.settlement.system.mapper.TblWpVendorUncommonShopConfigMapper;
import com.settlement.system.common.exception.ServiceException;
import com.settlement.system.model.entity.common.TblWpVendorConfig;
import com.settlement.system.service.ITblWpVendorConfigService;
import org.springframework.stereotype.Service;
import com.settlement.system.mapper.BaseMapper;
import org.springframework.transaction.annotation.Transactional;

import jakarta.annotation.Resource;
import java.util.List;

/**
 * 唯品会商户配置 服务实现类
 * @author Ximi
 * @since 2020-04-15
 */
@Service
public class TblWpVendorConfigServiceImpl extends BaseServiceImpl implements ITblWpVendorConfigService {

    @Resource
    private TblWpVendorConfigMapper tblWpVendorConfigMapper;

    @Resource
    private TblWpVendorUncommonShopConfigMapper tblWpVendorUncommonShopConfigMapper;

    @Override
    public BaseMapper init() {
        return tblWpVendorConfigMapper;
    }

    @Override
    @Transactional(rollbackFor = ServiceException.class)
    public Integer deleteMD(TblWpVendorConfig model) throws ServiceException {
        try {
            //删除主表
            tblWpVendorConfigMapper.deleteById(model);
            //删除明细表
            tblWpVendorUncommonShopConfigMapper.deleteByParentId(model.getId());
        } catch (Exception ex){
            throw new ServiceException("删除数据异常",ex);
        }
        return 1;
    }

    /**
     * 获取商户编码
     * @param shopNos 店铺编码
     * @return
     * @throws ServiceException
     */
    @Override
    public List<String> getVendorCodes(List<String> shopNos) throws ServiceException {
        try {
            return tblWpVendorConfigMapper.getVendorCodes(shopNos);
        } catch (Exception ex){
            throw new ServiceException("获取商户号数据异常",ex);
        }
    }

    @Override
    public TblWpVendorConfig getWpVendorByCode(String supplierNo) throws ServiceException {
        try {
            return tblWpVendorConfigMapper.getWpVendorByCode(supplierNo);
        } catch (Exception ex){
            throw new ServiceException("获取商户信息数据异常",ex);
        }
    }

    @Override
    public String getVendorCodeByBillNumber(String billNumber) throws ServiceException {
        try {
            return tblWpVendorConfigMapper.getVendorCodeByBillNumber(billNumber);
        } catch (Exception ex){
            throw new ServiceException("获取商户信息数据异常",ex);
        }
    }

    @Override
    public List<String> getAllShopNos() throws ServiceException {
        try {
            return tblWpVendorConfigMapper.getAllShopNos();
        } catch (Exception ex){
            throw new ServiceException("listShopNos error",ex);
        }
    }

    @Override
    public String getVendorCodeFromBillNumber(String billNumber) throws ServiceException {
        try {
            return tblWpVendorConfigMapper.getVendorCodeFromBillNumber(billNumber);
        } catch (Exception ex){
            throw new ServiceException("listShopNos error",ex);
        }
    }


    @Override
    public void updateStatus(TblWpVendorConfig params) throws ServiceException {
        try {
            tblWpVendorConfigMapper.updateStatus(params);
        } catch (Exception ex){
            throw new ServiceException("listShopNos error",ex);
        }
    }
}

